package com.example.springboottestservice.postprocessor;

import com.example.springboottestservice.beans.Cat;
import com.example.springboottestservice.beans.Dog;
import com.example.springboottestservice.beans.User;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.*;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author wuxinxin
 */
@Configuration
//@Import({BeanSelector.class,BeanImportBeanDefinitionRegistrar.class})
public class MyConfiguration {

    @Bean
    public Cat cat(){
        return new Cat();
    }
}

class BeanSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        //return new String[]{Cat.class.getName(), Dog.class.getName()};
        return new String[]{};
    }
}

class BeanImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {

        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
        rootBeanDefinition.setBeanClass(User.class);
        registry.registerBeanDefinition("user2",rootBeanDefinition);
    }
}


